<?php

namespace App\Http\Middleware;

use App\Models\BaseLog;
use Closure;

class AdminLog
{
    protected $except = [
        'admin/login',
        'admin/logout'
    ];

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //指定路由不需要记录
        if ($request->is(...$this->except)) {
            return $next($request);
        }

        //日志记录
        $user = auth()->user()->username ?? 'not login';
        (new BaseLog())->addMasterLog($user, $request->route()->getName(), $request->all());

        return $next($request);
    }
}
